# Generate DASH application entitled "Momentum analysis tool" with 6 tabs. # The first tab named "Strgy Analysis" has 2 rows. # On the first row are 5 elements laid out horizontally # The first element is a pulldown labeled "universe" with items labeled "D30", "N100", "SP500", "R1000" and "FAANNG" that defaults to "FAANNG". # The second element is a text field labeled "lags" that allows me to enter a list of comma delimited numbers and initialized with the string "1,3,6,12", # The third element is a pulldown labeled "member count" with 6 items labeled 1-6 that defaults to 6. # The fourth element is a text field labeled "months back" initialized to 12. # The fifth element is a check box labeled "Use Cache?" with a default value of "checked". # On the second row are 6 elements laid out horizontally # The first element is a "Submit" button. # The second element is a FinGPT markdown link which opens a new tab to https://huggingface.co/spaces/FinGPT/FinGPT-Forecaster # The third element is an Article markdown link which opens a new tab to https://docs.google.com/document/d/1WngnKvHFAc8qZEUGt3tBUvFrNFHfeRmHMCX76iD9XMY # The fourth element is a Log markdown link which opens a new tab to https://docs.google.com/spreadsheets/d/19C-EUB3YiLeyC06nJwEJ0mex6PutRfGGG2_ZqkxgAvw/edit?usp=sharing # The fifth element is a Help markdown link which opens a new tab to https://docs.google.com/document/d/128e_RkPohXNduVFvwEY0O0xnNi46lnN8Ad9l7uNBCL8/edit?usp=sharing # When "Submit" is pressed, the application calls strategyAnalysis passing (universe,lags,memberCount,monthsback=12,useCache) which returns a returnStd data frame , monthly Returns data frame and a recommendations data frame. # Please print the recommendations data frame in a dataframe area called "Results". # The second tab is labeled "Strgy rtn vs time" and displays a plotly express line chart where you pass in the monthly Returns data frame. # The third tab is labeled "Strgy rtn vs risk" and displays a plotly express scatter chart where you pass in the returnStd data frame and x="std", y="return",text="ticker". # The fourth tab named "Unvrse Analysis" has 2 rows. # On the first row are 4 elements laid out horizontally # The first element is a multiple select item labeled "universes" with items labeled "D30", "N100", "SP500", "R1000" and "FAANNG". All items are selected. # The second element is a text field labeled "lags(s)" initialized with the string "1,3,6,12;1,3,6,6;4-36". # The third element is a pulldown labeled "U member count" with 6 items labeled 1-6 that defaults to 6. # The fourth element is a text field labeled "U months back" initialized to 12. # On the second row is # a check box labeled "U Use Cache?" with a default value of "checked". # a "U Submit" button. # When "Submit" is pressed, the application calls univeseAnalysis passing (universes,lags,memberCount,monthsback=12,useCache) which returns a aggregatedReturnStd data frame, aggregatedMonthlyReturns data frame # and a aggregatedRecommendations data frame. # Please print the aggregatedRecommendations data frame in a dataframe area called "Results". # The fifth tab is labeled "Unvrse rtn vs time" and displays a plotly express line chart where you pass in the aggregatedMonthlyReturns data frame. # The sixth tab is labeled "Unvrse rtn vs risk" and displays a plotly express scatter chart where you pass in the aggregatedReturnStd data frame and x="std", y="return",text="ticker". # Do not generate a dummy call to strategyAnalysis # Instead create an "from momentumtiming import strategyAnalysis" import. # Do not pass a "key" argument to st.dataframe. # Do not pass x and y arguments to plotly. # Do not generate a target element for the links # And include this entire prompt as a comment in the header of the generated file. from dash import Dash, dcc, html, Input, Output, State, dash_table import dash_bootstrap_components as dbc import plotly.express as px from momentumtiming import strategyAnalysis, universeAnalysis app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP]) app.title = "Momentum analysis tool" tab1_content = dbc.Card( dbc.CardBody([ dbc.Row([ dbc.Col(dcc.Dropdown(id='universe', options=['D30', 'N100', 'SP500', 'R1000', 'FAANNG'], value='FAANNG', clearable=False)), dbc.Col(dcc.Input(id='lags', type='text', value='1,3,6,12')), dbc.Col(dcc.Dropdown(id='member-count', options=[{'label': i, 'value': i} for i in range(1, 7)], value=6, clearable=False)), dbc.Col(dcc.Input(id='months-back', type='number', value=12)), dbc.Col(dbc.Checkbox(id='use-cache', label='Use Cache?', value=True)) ]), dbc.Row([ dbc.Col(dbc.Button('Submit', id='submit-button', color='primary')), dbc.Col(dcc.Link('FinGPT', href='https://huggingface.co/spaces/FinGPT/FinGPT-Forecaster', target='_blank')), dbc.Col(dcc.Link('Article', href='https://docs.google.com/document/d/1WngnKvHFAc8qZEUGt3tBUvFrNFHfeRmHMCX76iD9XMY', target='_blank')), dbc.Col(dcc.Link('Log', href='https://docs.google.com/spreadsheets/d/19C-EUB3YiLeyC06nJwEJ0mex6PutRfGGG2_ZqkxgAvw/edit?usp=sharing', target='_blank')), dbc.Col(dcc.Link('Help', href='https://docs.google.com/document/d/128e_RkPohXNduVFvwEY0O0xnNi46lnN8Ad9l7uNBCL8/edit?usp=sharing', target='_blank')) ]), html.Div(id='results') ]) ) tab2_content = dbc.Card( dbc.CardBody([ dcc.Graph(id='strgy-rtn-vs-time') ]) ) tab3_content = dbc.Card( dbc.CardBody([ dcc.Graph(id='strgy-rtn-vs-risk') ]) ) tab4_content = dbc.Card( dbc.CardBody([ dbc.Row([ dbc.Col(dcc.Dropdown(id='universes', options=['D30', 'N100', 'SP500', 'R1000', 'FAANNG'], value=['D30', 'N100', 'SP500', 'R1000', 'FAANNG'], multi=True)), dbc.Col(dcc.Input(id='u-lags', type='text', value='1,3,6,12;1,3,6,6;4-36')), dbc.Col(dcc.Dropdown(id='u-member-count', options=[{'label': i, 'value': i} for i in range(1, 7)], value=6, clearable=False)), dbc.Col(dcc.Input(id='u-months-back', type='number', value=12)) ]), dbc.Row([ dbc.Col(dbc.Checkbox(id='u-use-cache', label='U Use Cache?', value=True)), dbc.Col(dbc.Button('U Submit', id='u-submit-button', color='primary')) ]), html.Div(id='u-results') ]) ) tab5_content = dbc.Card( dbc.CardBody([ dcc.Graph(id='unvrse-rtn-vs-time') ]) ) tab6_content = dbc.Card( dbc.CardBody([ dcc.Graph(id='unvrse-rtn-vs-risk') ]) ) app.layout = dbc.Container([ dbc.Tabs([ dbc.Tab(tab1_content, label="Strgy Analysis"), dbc.Tab(tab2_content, label="Strgy rtn vs time"), dbc.Tab(tab3_content, label="Strgy rtn vs risk"), dbc.Tab(tab4_content, label="Unvrse Analysis"), dbc.Tab(tab5_content, label="Unvrse rtn vs time"), dbc.Tab(tab6_content, label="Unvrse rtn vs risk"), ]) ]) @app.callback( [Output('results', 'children'), Output('strgy-rtn-vs-time', 'figure'), Output('strgy-rtn-vs-risk', 'figure')], [Input('submit-button', 'n_clicks')], [State('universe', 'value'), State('lags', 'value'), State('member-count', 'value'), State('months-back', 'value'), State('use-cache', 'value')] ) def update_strategy_analysis(n_clicks, universe, lags, member_count, months_back, use_cache): if n_clicks is None: return dash.no_update, dash.no_update, dash.no_update returnStd, monthlyReturns, recommendations = strategyAnalysis(universe, lags, member_count, months_back, use_cache) results_table = dash_table.DataTable( id='results-table', columns=[{"name": i, "id": i} for i in recommendations.columns], data=recommendations.to_dict('records') ) strgy_rtn_vs_time_fig = px.line(monthlyReturns) strgy_rtn_vs_risk_fig = px.scatter(returnStd, hover_data=['ticker']) return results_table, strgy_rtn_vs_time_fig, strgy_rtn_vs_risk_fig @app.callback( [Output('u-results', 'children'), Output('unvrse-rtn-vs-time', 'figure'), Output('unvrse-rtn-vs-risk', 'figure')], [Input('u-submit-button', 'n_clicks')], [State('universes', 'value'), State('u-lags', 'value'), State('u-member-count', 'value'), State('u-months-back', 'value'), State('u-use-cache', 'value')] ) def update_universe_analysis(n_clicks, universes, lags, member_count, months_back, use_cache): if n_clicks is None: return dash.no_update, dash.no_update, dash.no_update aggregatedReturnStd, aggregatedMonthlyReturns, aggregatedRecommendations = universeAnalysis(universes, lags, member_count, months_back, use_cache) results_table = dash_table.DataTable( id='u-results-table', columns=[{"name": i, "id": i} for i in aggregatedRecommendations.columns], data=aggregatedRecommendations.to_dict('records') ) unvrse_rtn_vs_time_fig = px.line(aggregatedMonthlyReturns) unvrse_rtn_vs_risk_fig = px.scatter(aggregatedReturnStd, hover_data=['ticker']) return results_table, unvrse_rtn_vs_time_fig, unvrse_rtn_vs_risk_fig if __name__ == '__main__': app.run_server(debug=True)